$(function(){
	//lrtkInit();
});

var winWidth=$(document).width();
var imgSpa=10;
var imgNum=3;
var imgWidth=0;

function lrtkInit()
{
	winWidth=$(document).width();
	
	imgSpa=10;
	imgNum=3;
	winWidth=winWidth-14;
	imgWidth=Math.ceil((winWidth-imgSpa*(imgNum-1))/imgNum) ;
	
	linum = $('.mainlist li').length;//图片数量
	w = linum * (imgWidth+imgSpa);//ul宽度
	$('.piclist').css('width', w + 'px');//ul宽度
	$('.swaplist').html($('.mainlist').html());//复制内容
	
	$('.og_next').click(function(){
		og_next();
	});
	$('.og_prev').click(function(){
		og_prev();
	});   
	
	
	$('.og_prev,.og_next').hover(function(){
		$(this).fadeTo('fast',1);
	},function(){
		$(this).fadeTo('fast',0.7);
	});
	
	$("#sliderDoctor").on("swipeleft",function(){
		  og_next();
	  });   
	  $("#sliderDoctor").on("swiperight",function(){
		  og_prev();
	  }); 
	  
	  //初始化样式
	 $(".box").each(function(){
		 $(this).css({"width":imgNum*(imgWidth+imgSpa)});
	 });
	 $(".picbox").each(function(){
		 $(this).css({"width":imgNum*(imgWidth+imgSpa),"height":((imgWidth*1.5)+6)});
	 });
	 $(".piclist").each(function(){
		 $(this).css({"height":imgWidth*1.5});
	 });
	 $("div#sliderDoctor ul li img").each(function(){
		 $(this).css({"width":(imgWidth-6),"height":((imgWidth*1.5)-6)});
	 });
	 $("div#sliderDoctor ul li div").each(function(){
		 $(this).css({"width":imgWidth,"height":imgWidth*1.5});
	 });
	
	if(linum==1)//只有一张图片的时候
	{
		$('.mainlist').css({left: (imgWidth+imgSpa)+'px'});
	}
	else if(linum==2)	 //只有两张图片的时候
	{
		$('.mainlist').css({left: Math.ceil((imgWidth+imgSpa)/2)+'px'});
	}
	else
	{
		$(".mainlist").css("left","0px");
	}
}

//右移
function og_next(){
	if($('.swaplist,.mainlist').is(':animated')){
		$('.swaplist,.mainlist').stop(true,true);
	}
	if($('.mainlist li').length>imgNum){//多于imgNum张图片
		ml = parseInt($('.mainlist').css('left'));//默认图片ul位置
		sl = parseInt($('.swaplist').css('left'));//交换图片ul位置
		if(ml<=0 && ml>w*-1){//默认图片显示时
			$('.swaplist').css({left: imgNum*(imgWidth+imgSpa)+'px'});//交换图片放在显示区域右侧
			$('.mainlist').animate({left: ml - imgNum*(imgWidth+imgSpa) + 'px'},'slow');//默认图片滚动				
			var spWidth=Math.abs(((w-(imgNum*(imgWidth+imgSpa)))*-1));
			var mlAbs=Math.abs(ml);
			if((spWidth-mlAbs)<=imgNum*(imgWidth+imgSpa))
			{
				$('.swaplist').animate({left: (spWidth-mlAbs)+'px'},'slow');
			}
		}else{//交换图片显示时
			$('.mainlist').css({left: imgNum*(imgWidth+imgSpa)+'px'});//默认图片放在显示区域右
			$('.swaplist').animate({left: sl - imgNum*(imgWidth+imgSpa) + 'px'},'slow');//交换图片滚动
			var spWidth=Math.abs(((w-(imgNum*(imgWidth+imgSpa)))*-1));
			var slAbs=Math.abs(sl);
			if((spWidth-slAbs)<=imgNum*(imgWidth+imgSpa))
			{
				$('.mainlist').animate({left: (spWidth-slAbs)+'px'},'slow');
			}
		}
	}
}

//左移
function og_prev()
{
	if($('.swaplist,.mainlist').is(':animated')){
		$('.swaplist,.mainlist').stop(true,true);
	}
	if($('.mainlist li').length>imgNum){
		ml = parseInt($('.mainlist').css('left'));
		sl = parseInt($('.swaplist').css('left'));
		if(ml<=0 && ml>w*-1){
			$('.swaplist').css({left: (w * -1) + 'px'});
			$('.mainlist').animate({left: (ml + imgNum*(imgWidth+imgSpa)) + 'px'},'slow');	
			var mlAbs=Math.abs(ml);
			if(mlAbs<imgNum*(imgWidth+imgSpa))
			{
				$('.swaplist').animate({left: ((w-(imgNum*(imgWidth+imgSpa)-mlAbs))*-1) + 'px'},'slow');
			}
		}else{
			$('.mainlist').css({left: (w * -1) + 'px'});
			$('.swaplist').animate({left: (sl + imgNum*(imgWidth+imgSpa)) + 'px'},'slow');
			var slAbs=Math.abs(sl);
			if(slAbs<imgNum*(imgWidth+imgSpa))
			{
				$('.mainlist').animate({left: ((w-(imgNum*(imgWidth+imgSpa)-slAbs))*-1) + 'px'},'slow');
			}
		}
	}
}

